<template>
  <div>
        <input class="input"   type="text" placeholder="输入标签" 
        :value="value" @blur="dealblur"
        @keyup.enter="$event.target.blur()"
        v-if="flag"
        v-focus/>
        <div class="text"
        v-else
        @dblclick="fn" >{{value}}</div>
   </div>
</template>
 
<script>
export default {
  name: "MyTag",
  components: {},
  props: {
    value:{
        type:String,
        required:true
    }
  },
  data() {
    return {
        flag:false
    };
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    dealblur(e){
        if(e.target.value){
            this.$emit("input",e.target.value)
        }else{
            alert('输入不能为空')
        }
        this.flag=false
    },
    fn(){
        //window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
        this.flag=true
    }
  }
};
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}  
</style>